package org.corey.wyp.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	
	import org.corey.wyp.business.PropertyManagerDelegate;
	import org.corey.wyp.event.SettingTemplateGetterEvent;
	import org.corey.wyp.event.SettingTemplateSaveEvent;
	import org.corey.wyp.vo.SettingTemplate;
	import org.corey.wyp.vo.SettingTemplateType;
	
	public class SettingTemplateSaveCommand implements ICommand,IResponder
	{
		private var settingType:String;
		private var settingTemplate:SettingTemplate;
		public function SettingTemplateSaveCommand()
		{
		}
		
		public function execute(event:CairngormEvent):void{
			var saveEvent:SettingTemplateSaveEvent=SettingTemplateSaveEvent(event);
			settingTemplate=saveEvent.settingTemplate;
			settingType=saveEvent.settingType;
			var pm:PropertyManagerDelegate=new PropertyManagerDelegate(this);
			pm.saveSettingTemplate(settingType,settingTemplate);
		}
		
		public function result(event:Object):void{
			var st:SettingTemplate=SettingTemplate(event.result);
			if(st!=null){
				if(SettingTemplateType.DAY==settingType){
					CairngormEventDispatcher.getInstance().dispatchEvent(new SettingTemplateGetterEvent(SettingTemplateType.DAY));
				}else if(SettingTemplateType.MONTH==settingType){
					CairngormEventDispatcher.getInstance().dispatchEvent(new SettingTemplateGetterEvent(SettingTemplateType.MONTH));
				}
			}
		}
		
		public function fault(info:Object):void{
			Alert.show("增加信息失败:"+info);
		}

	}
}